<script src="../../main.js"></script>
<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-picture-outline"></i> 意见反馈管理
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-table
                    :data="tableData"
                    border
                    class="table"
                    ref="multipleTable"
                    header-cell-class-name="table-header"
                    @selection-change="handleSelectionChange"
            >
                <el-table-column prop="id" label="意见id" width="80" align="center"></el-table-column>
                <el-table-column prop="question" show-overflow-tooltip align="center" label="问题和意见"></el-table-column>
                <el-table-column prop="linkMsg" show-overflow-tooltip label="联系方式" align="center"></el-table-column>
                <el-table-column label="图片"  width="80" align="center">
                    <template slot-scope="scope">
                        <el-button
                                type="text"
                                icon="el-icon-lx-attention"
                                @click="handleImage(scope.row.id,scope.row.imgs)"
                        >查看</el-button>
                    </template>
                </el-table-column>
                <el-table-column prop="status"  width="80" label="状态" align="center">
                    <template slot-scope="scope">
                        <el-tag v-if="scope.row.status==0" type="info">未处理</el-tag>
                        <el-tag v-if="scope.row.status==1" type="warning">已处理</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="createdTime"  width="160"  label="创建时间" align="center"></el-table-column>
                <el-table-column label="操作" width="100"  align="center">
                    <template slot-scope="scope">
                        <el-button
                                type="text"
                                icon="el-icon-edit"
                                @click="handleDelete(scope.row.id,scope.row)"
                                v-if="globalPermission.advise.edit && scope.row.status==0"
                        >办理
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                        background
                        layout="total, prev, pager, next"
                        :current-page="query.pageNum"
                        :page-size="query.pageSize"
                        :total="pageTotal"
                        @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <!-- 图片 -->
        <el-dialog title="反馈图片" :visible.sync="imageVisible" width="40%">
            <el-table
                    :data="picData"
                    border
                    class="table"
                    ref="multipleTable"
                    header-cell-class-name="table-header"
            >
                <el-table-column prop="imageName" label="图片(点击预览大图)" align="center">
                    <template slot-scope="scope">
                        <el-image
                                class="table-td-thumb"
                                :src="picData[0]"
                                :preview-src-list="picData"
                        ></el-image>
                    </template>
                </el-table-column>
            </el-table>
        </el-dialog>
    </div>
</template>

<script>
    import {getAll,editModel} from '../../api/advise';
    var queryRequest = {url: "/manager/customer/getSysAdvise"};
    var editRequest = {url:"/manager/customer/updateSysAdvise"};
    export default {
        name: 'usertable',
        data() {
            return {
                query: {
                    title: '',
                    pageNum: 1,
                    pageSize: 10,
                },
                statusQuery:{
                    id:'',
                    status
                },
                uploadData:null,
                picData :[],
                globalPermission: this.getPermission(),
                getToken:{'auth-token':localStorage.getItem('token')},
                tableData: [],
                multipleSelection: [],
                delList: [],
                editVisible: false,
                editRolesVisible: false,
                formIdShow: false,
                pageTotal: 0,
                imageVisible:false,
                picData:[],
                form: {},
                statusForm:{},
                idx: -1,
                id: -1,
                isCurEdit:false,
            };
        },
        created() {
            queryRequest.data = this.query;
            this.getData();
        },
        methods: {
            // 获取数据
            getData() {
                //获取新闻列表
                getAll(queryRequest).then(res => {
                    this.tableData = res.data.list;
                    this.pageTotal = res.data.total;
                });
            },

            clean(){
                this.editVisible=false;
                this.handleSearch();
            },
            getPermission() {
                return JSON.parse(sessionStorage.getItem("permission"));
            },

            // 触发搜索按钮
            handleSearch() {
                this.$set(this.query, 'pageNum', 1);
                this.getData();
            },
            // 编辑操作
            handleEdit(id, row) {
                this.id = id;
                this.form = row;
                this.form.id = this.id;
                this.editVisible = true;
                this.isCurEdit = true;
            },
            refreshPic(response){
                this.handleSearch();
            },
            beforeUpload (file) {
                this.uploadData = {id:this.id};
                let promise = new Promise((resolve) => {
                    this.$nextTick(function () {
                        resolve(true);
                    });
                });
                return promise; //通过返回一个promis对象解决
            },
            // 多选操作
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },

            // 新增
            addItem() {
                this.form={};
                this.isCurEdit = false;
                this.editVisible = true;
            },
            // 删除操作
            handleDelete(id, row) {
                // 二次确认删除
                this.$confirm("你确定已处理了吗", '提示', {
                    type: 'warning'
                }).then(() => {
                    this.form.id = id;
                    editRequest.data = this.form;
                    editModel(editRequest).then(res => {
                        if (res.code == 0) {
                            this.$message.success(`成功`);
                            this.editVisible = false;
                            this.handleSearch();
                        } else {
                            this.$message.error(res.message);
                        }
                    });
                }).catch(() => {
                });
            },
            // 打开图片窗口
            handleImage(id,url) {
                this.id=id;
                this.picData[0]=url;
                this.imageVisible = true;
            },
            // 分页导航
            handlePageChange(val) {
                this.$set(this.query, 'pageNum', val);
                this.getData();
            }
        }
    };
</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 130px;
        display: inline-block;
    }

    .table {
        width: 100%;
        font-size: 14px;
    }

    .red {
        color: #ff0000;
    }

    .mr10 {
        margin-right: 10px;
    }

    .table-td-thumb {
        display: block;
        margin: auto;
        width: 40px;
        height: 40px;
    }

    .show {
        display: block;
    }

    .hide {
        display: none;
    }

    .checkbox-rows {
        width: 130px;
        margin-top: 10px;
    }

    .el-checkbox.is-bordered + .el-checkbox.is-bordered {
        margin-left: 0px;
    }
</style>
